using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using Pay.DTO.tenPay;

namespace Pay.Service.AutoMapper {
	public class PayHtmlMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public PayHtmlMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<pay_html_dto, PayHtml>()
				.ForMember(dest => dest.OrderNo, src => src.MapFrom(c => c.order_no))
                .ForMember(dest => dest.PayType, src => src.MapFrom(c => c.pay_type))
                .ForMember(dest => dest.IsFinish, src => src.MapFrom(c => c.is_finish))
                .ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no))
				.ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()));
			_cfg.CreateMap<PayHtml, pay_html_dto>()
				.ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
                .ForMember(dest => dest.pay_type, src => src.MapFrom(c => c.PayType))
                .ForMember(dest => dest.is_finish, src => src.MapFrom(c => c.IsFinish))
                .ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.MerchantNo))
				.ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()));
			_cfg.CreateMap<pay_html_model, PayHtml>()
				.ForMember(dest => dest.OrderNo, src => src.MapFrom(c => c.order_no))
                .ForMember(dest => dest.PayType, src => src.MapFrom(c => c.pay_type))
				.ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no));
			_cfg.CreateMap<pay_html_dto, payment_data>()
				.ForMember(dest => dest.account_name, src => src.MapFrom(c => c.html.ToObject<payment_data>().account_name))
				.ForMember(dest => dest.account_no, src => src.MapFrom(c => c.html.ToObject<payment_data>().account_no))
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.amount, src => src.MapFrom(c => c.html.ToObject<payment_data>().amount))
				.ForMember(dest => dest.rateAmount, src => src.MapFrom(c => c.html.ToObject<payment_data>().rateAmount))
				.ForMember(dest => dest.mobile, src => src.MapFrom(c => c.html.ToObject<payment_data>().mobile))
				.ForMember(dest => dest.data, src => src.MapFrom(c => c.html.ToObject<payment_data>().data))
				.ForMember(dest => dest.id_card, src => src.MapFrom(c => c.html.ToObject<payment_data>().id_card));
		}
	}
}
